package com.xiaoq.web;

import java.io.IOException;
import java.util.Date;

import org.apache.commons.lang3.time.DateFormatUtils;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

public class DateSerializer extends JsonSerializer<Date> {

	@Override
	public void serialize(Date d, JsonGenerator jg,
			SerializerProvider p) throws IOException,
			JsonProcessingException {
		if(d != null) {
			jg.writeString(DateFormatUtils.format(d, "yyyy-MM-dd HH:mm:ss"));
		}
	}
}
